package com.buaa.airticketbookingsystem.Controller;

import com.buaa.airticketbookingsystem.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
@CrossOrigin
@RestController
public class ChangePasswordController {

    @Autowired
    private UserService userService;

    @PostMapping("/changePassword")
    public Map<String, Object> changePassword(@RequestBody Map<String, String> remap){
        Map<String, Object> map = new HashMap<>();
        String email = remap.get("email");
        String password = remap.get("password");
        String new_password = remap.get("new_password");
        try {
            userService.changeUserPassword(email, new_password);
            map.put("res", true);
            map.put("message", "修改密码成功！");
        }
        catch (Exception e) {
            map.put("res", false);
            map.put("message", "修改密码失败！");
        }
        return map;
    }
}